

window.onload = function () {

    //#region wow.js
    var wow = new WOW({
        boxClass: 'wow', // default
        animateClass: 'animate__animated', // default
        offset: 0, // default
        mobile: true, // default
        live: true // default
    })
    wow.init();
    //#endregion

    //#region  内页导航页变透明
    if($('.page_main').length>0){
        var index_head=$('.index_head')
        index_head.addClass('page_head')
    }
    if($('.detail_page').length>0){
        var index_head=$('.index_head')
        index_head.removeClass('page_head')
    }
    //#endregion

  //#region 首页产品切换
  
  $('.product_title').each(function(){
    if($(this).hasClass('current')){
      i = $(this).index();
      $('.product_items').eq(i).removeClass('product_items_show');
    }
    $(this).click(function(){
      k = $(this).index();
      $(this).addClass('current');
      $(this).siblings().removeClass('current');
     $(this).parents('.proWrap').find('.product_items').eq(k).removeClass('product_items_show');
     $(this).parents('.proWrap').find('.product_items').eq(k).siblings().addClass('product_items_show');
    })
  })


    //#region 
    var itemSwiper = new Swiper ('.itemswiper', {
        slidesPerView : 5,  
        // loop:true,
        spaceBetween : 20,
        // speed:4000,
        // autoplay: {
        //     delay: 0,
        //     disableOnInteraction:true,
        //     stopOnLastSlide:false
        //   },
          navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
          },
        // 如果需要分页器
       
      })        
    //#endregion

    //#region 全局搜索search
        document.documentElement.className = 'js';; (function (window) {
            if (document.querySelector('.web-search')) {
                'use strict'; var mainContainer = document.querySelector('.container'), searchContainer = document.querySelector('.web-search'), openCtrl = document.getElementById('btn-search'), closeCtrl = document.getElementById('btn-search-close'), inputSearch = searchContainer.querySelector('.search-ipt'); function init() { initEvents() } function initEvents() {
                    openCtrl.addEventListener('click', function () { if (!searchContainer.classList.contains("search--open")) { openSearch(); } else { closeSearch(); } });
                    closeCtrl.addEventListener('click', closeSearch); document.addEventListener('keyup', function (ev) { if (ev.keyCode == 27) { closeSearch() } })
                } function openSearch() { mainContainer.classList.add('main-wrap--move'); searchContainer.classList.add('search--open'); setTimeout(function () { inputSearch.focus() }, 600) } function closeSearch() { mainContainer.classList.remove('main-wrap--move'); searchContainer.classList.remove('search--open'); inputSearch.blur(); inputSearch.value = '' } init()
            }
        })(window);
    //#endregion

    //#region 菜单生产三角号
    var head_nav = $('.web_nav > ul > li')
    //    var a_nav=$('.web_nav > ul > li > a')
    for (let s = 0; s < head_nav.length; s++) {
        if (head_nav[s].getElementsByTagName("ul").length > 0) {
            var span = document.createElement('b')
            // span.innerHTML="▼"
            // console.log( head_nav[s].childNodes);
            head_nav[s].childNodes[1].append(span);
        }
    }

    var head_nav_2 = $('.web_nav > ul > li> ul >li')
    for (let w = 0; w < head_nav_2.length; w++) {
        if (head_nav_2[w].getElementsByTagName("ul").length > 0) {
            var span = document.createElement('b') 
            head_nav_2[w].childNodes[1].append(span);
        }
    }
    //#endregion

    //#region 首页banner
    //    banner

   var swiper=  new Swiper ('.swiper', {
        effect: 'fade',
        loop: true, // 循环模式选项
        autoplay: {
            delay: 4000,
            disableOnInteraction: false,
          },
          speed:1000,
      })   
    //#endregion

  
   
    

    //#region  历史
    if($('.about_history').length>0){
        jQuery(".slide").slide({trigger:"click",delayTime:0,defaultIndex:0});
        if(window.innerWidth>980){
            
            var mySwiper = new Swiper ('.swiper_history', {
                slidesPerView:3,
                initialSlide: 0,
                allowTouchMove:false,
                // 如果需要前进后退按钮
                navigation: {
                nextEl: '.swiper-button-next',
                prevEl: '.swiper-button-prev',
                },
            
            })  
        }else if(window.innerWidth<980){
            var mySwiper = new Swiper ('.swiper_history', {
                slidesPerView:3,
                initialSlide: 0,
                allowTouchMove:false,
                // 如果需要前进后退按钮
                navigation: {
                nextEl: '.swiper-button-next',
                prevEl: '.swiper-button-prev',
                },
            
            })  
        }

    
    } 
    jQuery(".slideTxtBox").slide({});

    //#endregion   
    
    //#region 
    var mySwiper = new Swiper ('.loveswiper', {
        // loop: true, // 循环模式选项
        slidesPerView: 1,
        spaceBetween: 30,
        breakpoints:{
            1350:{
                slidesPerView: 2.7,
            },
            1150:{
                slidesPerView: 2.2,
            },
            950:{
                slidesPerView: 1.5,
            }
        },
        // 如果需要前进后退按钮
        navigation: {
          nextEl: '.swiper-button-next',
          prevEl: '.swiper-button-prev',
        },
       
      })   
      //#endregion     

    //#region 荣誉资质 
    var num =4
        if(window.innerWidth>1280){
            num=4
        } else if(window.innerWidth>950){
            num=3
        }else if(window.innerWidth<950){
            num=2
        }

        new Swiper(".honor_swiper", {
            slidesPerView: num,
            spaceBetween: 20,
            // 如果需要前进后退按钮
            navigation: {
                nextEl: '.swiper-button-next',
                prevEl: '.swiper-button-prev',
            },
            pagination: {
                el: '.swiper-pagination',
            },
        });
    
    

    //#endregion

    //#region 产品侧边栏滚动产品
    new Swiper ('.pro_swiper', {
        direction: 'vertical', // 垂直切换选项
    //   loop: true, // 循环模式选项
        slidesPerView: 3,
        spaceBetween: 30,
        slidePerGroup: 1,
        // 如果需要分页器
        pagination: {
        el: '.swiper-pagination',
        },
        
        // 如果需要前进后退按钮
        navigation: {
        nextEl: '.swiper-button-next',
        prevEl: '.swiper-button-prev',
        },
        
        // 如果需要滚动条
        scrollbar: {
        el: '.swiper-scrollbar',
        },
    })   
    //#endregion     
        
    //#region 产品页swiper

    var swiper = new Swiper(".Smallswiper", {
        spaceBetween: 10,
        slidesPerView: 3.3,
        freeMode: true,
        watchSlidesProgress: true,
    });
    var swiper2 = new Swiper(".Bigswiper", {

        spaceBetween: 10,
        thumbs: {
            swiper: swiper,
        },
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        },
    });

    //#endregion

    //#region 数字跳动
        var window_height = document.documentElement.clientHeight
        var adoutNum = $('.aboutNum')
        var num = document.querySelectorAll('.numadd')
        var slop = false
        window.onscroll = function () {
            if (slop) return
            // 数字跳动
            var scrollTop = document.documentElement.scrollTop || document.body.scrollTop
            if ($('.aboutNum').length > 0) {
                if (scrollTop >= adoutNum.offset().top - window_height && scrollTop <= adoutNum.offset().top) {
                    slop = true
                    for (let i = 0; i < num.length; i++) {
                        const numadd = num[i];
                        numadd.classList.add('timer');
                        // 动态数字触发
                        $('.timer').each(count);
                        function count(options) {
                            var $this = $(this);
                            options = $.extend({}, options || {}, $this.data('countToOptions') || {});
                            $this.countTo(options);
                        }
                    }
                }
            }
        }
    //#endregion

    //#region faq

    if ($('#faq').length > 0) {
    // 左侧faq
        var liList1 = $('.news_faq>.left>ul>li')
        var answerList1 = $('.left>ul>li>.answer')
        var btext1 = $('.news_faq>.left>ul>li>.question>b')
        //设置所有的b都是∨
        btext1.text('∨')
        // 设置第一个展示    
        liList1[0].classList.add('block')
        // 循环所有问题   
        for (var i = 0; i < liList1.length; i++) {
            liList1[i].onclick = function () {
                // 如果问题下的答案是关上的
                if ($(this).find('.answer').css('display') == 'none') {
                    // 排他 设置所有的答案都是不展示
                    answerList1.css('display', 'none')
                    // 排他 设置所有的类名都是没有block
                    liList1.removeClass('block')
                    // 当前的b设置成∨
                    // 当前的答案设置成展示
                    $(this).find('.answer').slideDown(150)
                    $(this).addClass('block')
                
                } else {
                    $(this).find('.answer').slideUp(150)
                    $(this).removeClass('block')
                }

            }
        }
    // 右侧faq

    var liList2 = $('.news_faq>.right>ul>li')
    var answerList2 = $('.right>ul>li>.answer')
    var btext2 = $('.news_faq>.right>ul>li>.question>b')
    //设置所有的b都是∨
    btext2.text('∨')
    // 设置第一个展示    
    liList2[0].classList.add('block')
    // 循环所有问题   
    for (var i = 0; i < liList2.length; i++) {
        liList2[i].onclick = function () {
            // 如果问题下的答案是关上的
            if ($(this).find('.answer').css('display') == 'none') {
                // 排他 设置所有的答案都是不展示
                answerList2.css('display', 'none')
                // 排他 设置所有的类名都是没有block
                liList2.removeClass('block')
                // 当前的b设置成∨
                // 当前的答案设置成展示
                $(this).find('.answer').slideDown(150)
                $(this).addClass('block')
            
            } else {
                $(this).find('.answer').slideUp(150)
                $(this).removeClass('block')
            }

        }
    }

    }
    //#endregion

}

//#region 多语言

$(document).ready(function () {
    $('.change-language .change-language-cont').append("<div class='change-empty'>Untranslated</div>")
    $('.prisna-wp-translate-seo').append("<div class='lang-more'>More Language</div>")
    if ($('body .prisna-wp-translate-seo').length > 0 && $('.change-language .prisna-wp-translate-seo').length < 1) {
        $('.prisna-wp-translate-seo').appendTo('.change-language .change-language-cont')
        if ($('.change-language .change-language-cont .prisna-wp-translate-seo li').length > 0) {
            $('.change-language .change-language-cont .change-empty').hide()
            $('.change-language .change-language-cont .prisna-wp-translate-seo li').each(function (index) {
                if (index > 35) {
                    $(this).addClass('lang-item lang-item-hide')
                    $('.change-language-cont').find('.lang-more').fadeIn()
                } else {
                    $('.change-language-cont').find('.lang-more').fadeOut()
                }
            })
            if ($('.change-language-cont .lang-more').length > 0) {
                $('.change-language-cont .lang-more').click(function () {
                    if ($(this).parents('.change-language-cont').find('.prisna-wp-translate-seo li.lang-item').hasClass('lang-item-hide')) {
                        $(this).parents('.change-language-cont').find('.prisna-wp-translate-seo li.lang-item').removeClass('lang-item-hide')
                        $(this).addClass('more-active').text('×')
                    } else {
                        $(this).parents('.change-language-cont').find('.prisna-wp-translate-seo li.lang-item').addClass('lang-item-hide')
                        $(this).removeClass('more-active').text('More Language')
                    }
                })
            }
        } else {
            $('.change-language .change-language-cont .change-empty').fadeIn()
        }
    }
})
//#endregion

//#region  web导航

var $nav = $('.page_head'),
    navTop = $('.web_nav').offset().top,
    headH = $nav.outerHeight(),
    winTop_1 = 0, 
    winWidth = $(window).width(), 
    winHeight = $(window).height(), 
    spr = $('body').height() - $nav.height(), 
    holder = jQuery('<div class="head_holder">');
$(window).on('scroll', function () {
    var winTop_2 = $(window).scrollTop();
    holder.css('height', headH);

    if (winTop_2 > headH && winWidth > 980) {
        holder.show().appendTo($nav);
        $nav.addClass('fixed-nav');
        $nav.parents('body').addClass('fixed-body');
        setTimeout(function () { $nav.addClass('fixed-nav-active') });
    } else {
        holder.hide();
        $nav.removeClass('fixed-nav fixed-nav-active');
        $nav.parents('body').removeClass('fixed-body');
    }

    if (winTop_2 > winTop_1 && winWidth > 980) {
        $nav.removeClass('fixed-nav-appear');
    } else if (winTop_2 < winTop_1) {
        $nav.addClass('fixed-nav-appear');
    }
    winTop_1 = $(window).scrollTop();
})
//#endregion

//#region 手机端导航

function mSizeChange() {
    if (window.innerWidth)
        winWidth = window.innerWidth;
    else if ((document.body) && (document.body.clientWidth))
        winWidth = document.body.clientWidth;
    if (window.innerHeight)
        winHeight = window.innerHeight;
    else if ((document.body) && (document.body.clientHeight))
        winHeight = document.body.clientHeight;
    if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth) {
        winHeight = document.documentElement.clientHeight;
        winWidth = document.documentElement.clientWidth;
    }
    if (winWidth <= 930) {
        if ($('.mobile-head-items').length < 1) {
            var mobileService = '<div class="mobile-head-items"><div class="mobile-head-item mobile-head-nav"><div class="title"></div><div class="main-content-wrap side-content-wrap"><div class="content-wrap"></div></div></div><div class="mobile-head-item mobile-head-language"><div class="title"></div><div class="main-content-wrap side-content-wrap"><div class="content-wrap"></div></div></div><div class="mobile-head-item mobile-head-search"><div class="title"></div><div class="main-content-wrap middle-content-wrap"><div class="content-wrap"></div></div></div>'
            $('body').append(mobileService)
            if ($('body .aside').length > 0) {
                $('.mobile-head-items').append('<div class="mobile-head-item mobile-head-aside"><div class="title"></div><div class="main-content-wrap side-content-wrap"><div class="content-wrap"></div></div></div>')
            }
            $('.mobile-head-item').each(function () {
                $(this).find('.title').click(function () {
                    if ($(this).parents('.mobile-head-item').find('.main-content-wrap').length > 0) {
                        var pItem = $(this).parents('.mobile-head-item')
                        if (!pItem.find('.main-content-wrap').hasClass('show-content-wrap')) {
                            pItem.find('.main-content-wrap').addClass('show-content-wrap')
                            pItem.find('.side-content-wrap').stop().animate({ 'left': '0' }, 300)
                            pItem.find('.middle-content-wrap').addClass('middle-show-content-wrap')
                            pItem.find('.side-content-wrap').append("<b class='mobile-ico-close'></b>")
                            pItem.siblings('.mobile-head-item').find('.main-content-wrap').removeClass('show-content-wrap')
                            pItem.siblings('.mobile-head-item').find('.side-content-wrap').stop().animate({ 'left': '-70%' }, 300)
                            pItem.siblings('.mobile-head-item').find('.middle-content-wrap').removeClass('middle-show-content-wrap')
                            pItem.siblings('.mobile-head-item').find('.side-content-wrap .mobile-ico-close').remove()
                            if ($('.mobile-head-items').find('.mobile-body-mask').length < 1) {
                                $('.mobile-head-items').append('<div class="mobile-body-mask"></div>')
                            }
                        }
                        else {
                            pItem.find('.main-content-wrap').removeClass('show-content-wrap')
                            pItem.find('.side-content-wrap').stop().animate({ 'left': '-70%' }, 300)
                            pItem.find('.middle-content-wrap').removeClass('middle-show-content-wrap')
                            pItem.find('.side-content-wrap .mobile-ico-close').remove()
                        }
                        $('.mobile-body-mask').click(function () {
                            $('.mobile-body-mask').remove()
                            $('.mobile-head-item .main-content-wrap').removeClass('show-content-wrap')
                            $('.mobile-head-item .side-content-wrap').animate({ 'left': '-70%' }, 300)
                            $('.mobile-head-item .middle-content-wrap').removeClass('middle-show-content-wrap')
                            $('.mobile-head-item .side-content-wrap .mobile-ico-close').remove()
                        })
                        $('.mobile-ico-close').click(function () {
                            $('.mobile-body-mask').remove()
                            $('.mobile-head-item .main-content-wrap').removeClass('show-content-wrap')
                            $('.mobile-head-item .side-content-wrap').stop().animate({ 'left': '-70%' }, 300)
                            $('.mobile-head-item .middle-content-wrap').removeClass('middle-show-content-wrap')
                            $('.mobile-head-item .side-content-wrap .mobile-ico-close').remove()
                        })
                    }
                })
            })
            $('.change-currency ').clone().appendTo('.mobile-head-item.mobile-head-currency .main-content-wrap .content-wrap')
            $('.change-language .change-language-cont').clone().appendTo('.mobile-head-item.mobile-head-language .main-content-wrap .content-wrap')
            $('.web_nav>ul').clone().appendTo('.mobile-head-item.mobile-head-nav .main-content-wrap .content-wrap')
            $('.head-search:last').clone().appendTo('.mobile-head-item.mobile-head-search .main-content-wrap .content-wrap')
            $('.head_sns').clone().appendTo('.mobile-head-item.mobile-head-social .main-content-wrap .content-wrap')
            $('.aside .aside-wrap').clone().appendTo('.mobile-head-item.mobile-head-aside .main-content-wrap .content-wrap')
        }
    }
    //mobile end
    else {
        $(document).ready(function () {
            $('.mobile-body-mask,.mobile-head-items,.mobile-head-items,.mobile-nav-items,.mobile-cart-items,.mobile-tab-items').remove()
        });
    }
}
$(function () { mSizeChange(); })
$(window).resize(function () { mSizeChange() });

//#endregion

//#region /*side*/
$(function(){
    $('.side-widget .side-cate li').each(function(){
            if($(this).find('ul').length>0){
                $(this).append("<span class='icon-cate icon-cate-down'></span>")
                $(this).children('.icon-cate').click(function(e){
                                if($(this).parent('li').children('ul').is(':hidden')){
                                    $(this).parent('li').children('ul').slideDown(100);
                                        $(this).removeClass('icon-cate-down').addClass('icon-cate-up');
                                    }else{
                                        $(this).parent('li').children('ul').slideUp(100);
                                        $(this).removeClass('icon-cate-up').addClass('icon-cate-down');
                                        }
                                        e.stopPropagation();
                                })
                }
            })
        
            if($('.side-widget .side-cate .nav-current').parents('ul').length>0 && $('.side-widget .side-cate .nav-current').find('ul').length>0) {
            $('.side-widget .side-cate .nav-current').parents('ul').show()
            $('.side-widget .side-cate .nav-current').parents('li').addClass("show_li")
            $('.side-widget .side-cate .nav-current').parents('li.show_li').children('.icon-cate').removeClass('icon-cate-down').addClass('icon-cate-up')
            $('.side-widget .side-cate .nav-current').children('ul').show()
            $('.side-widget .side-cate .nav-current ').children('.icon-cate').removeClass('icon-cate-down').addClass('icon-cate-up');
            }
             else if($('.side-widget .side-cate .nav-current').parents('ul').length>0 && $('.side-widget .side-cate .nav-current').find('ul').length<1){
                 $('.side-widget .side-cate .nav-current').parents('ul').show()
                 $('.side-widget .side-cate .nav-current').parents('li').addClass("show_li")
                 $('.side-widget .side-cate .nav-current').parents('li.show_li').children('.icon-cate').removeClass('icon-cate-down').addClass('icon-cate-up')
                }
             else if($('.side-widget .side-cate .nav-current').parents('ul').length<1 && $('.side-widget .side-cate .nav-current').find('ul').length>0){
                $('.side-widget .side-cate .nav-current').children('ul').show()
                $('.side-widget .side-cate .nav-current').children('.icon-cate').removeClass('icon-cate-down').addClass('icon-cate-up');
                }
    })
//#endregion

//#region  滚动到头部

var mHeadTop = $('.index_head').offset().top
var $backToTopTxt = "TOP",
    $backToTopEle = $('<span class="gotop"></span>').appendTo($("body"))
        .html('<em>' + $backToTopTxt + '</em>').attr("title", $backToTopTxt).click(function () {
            $("html, body").animate({ scrollTop: 0 }, 600);
        }),
    $backToTopFun = function () {
        var st = $(document).scrollTop(),
            winh = $(window).height();
        (st > mHeadTop) ? $backToTopEle.addClass('active') : $backToTopEle.removeClass('active');
        if (!window.XMLHttpRequest) {
            $backToTopEle.css("top", st + winh - 210);
        }
    };
$(window).bind("scroll", $backToTopFun);
$(function () { $backToTopFun(); });

//#endregion
